home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************************
- File: Dialogs.c
-
- History...
- xxx RMF Created from DTS source files,
- Created InitSetCompression() routine to eliminate globals
- 94/2/9 RMF Fix up preview window so it did not move or close and reopen,
- Add option for next preview image
-
- */
- #include "gGlobals.h"
-
- #include <pascal.h>
- #include <Scrap.h>
- #include <Desk.h>
- #include <string.h>
- #include <stdio.h>
- #include <Fonts.h>
- #include <Math.h>
-
- /*********************************************
-
- Allow the user to set the compression parameters with the standard compression dialog.
-
- *********************************************/
-
- void InitSetCompression()
- {
- gStandardP.flags = scShowMotionSettings;
- gStandardP.theCodecType = kCodecType;
- gStandardP.theCodec = kCodecID;
- gStandardP.spatialQuality = kCodecQuality;
- gStandardP.temporalQuality = 0;
- gStandardP.depth = kCodecDepth;
- gStandardP.frameRate = kFrameRate<<16;
- gStandardP.keyFrameRate = kFrameRate;
- } /* End of () */
-
- /*********************************************
-
- Allow the user to set the compression parameters with the standard compression dialog.
-
- *********************************************/
-
- SetCompression()
- { ComponentInstance ci;
- Point where;
-
- where.h = where.v = -2;
- ci = OpenDefaultComponent(StandardCompressionType,0);
- if ( ci == nil ) {
- Error("Couldn't open StdCompression",0); return;
- }
-
- SCGetCompression(ci,&gStandardP,where);
-
- } /* End of () */
-
- /***********************************************************************************
-
- Allow the user to set the number of stages she wants the processing to take.
- */
- SetStages()
- {
- #define STAGE_DLOG 128
- #define IT_STAGES 3
- #define IT_LINEAR 4
- #define IT_OK 1
- #define IT_CANCEL 2
-
- CGrafPtr savePort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit,lastItem = -1;
- Boolean done = false;
- Point tp;
- GDHandle saveGD;
- Str255 text;
- long num;
- long stageCount = gNumberSteps;
- Boolean linear = true;
-
- if ((theDialog = GetNewDialog(STAGE_DLOG, nil, (WindowPtr) -1)) == nil )
- return;
-
- GetMouse(&tp);
- GetGWorld(&savePort,&saveGD);
- SetPort(theDialog);
- GetDItem(theDialog,IT_OK,&itemType,&itemHdl,&itemRect);
- PenSize(3,3);
- InsetRect(&itemRect,-4,-4);
- FrameRoundRect(&itemRect,16,16);
-
-
- GetDItem(theDialog,IT_STAGES,&itemType,&itemHdl,&itemRect);
- NumToString(stageCount, text);
- SetIText(itemHdl,text);
-
- SelIText(theDialog,IT_STAGES,0,32767);
-
- GetDItem(theDialog,IT_LINEAR,&itemType,&itemHdl,&itemRect);
- SetCtlValue((ControlHandle)itemHdl,linear);
- HiliteControl((ControlHandle)itemHdl,255);
-
- while ( !done ) {
- ModalDialog(nil, &itemHit);
- if ( itemHit != lastItem ) {
- switch( lastItem ) {
- case IT_STAGES :
- GetDItem(theDialog,IT_STAGES,&itemType,&itemHdl,&itemRect);
- GetIText(itemHdl,text);
- StringToNum(text, &num);
- if ( num > 0 ) stageCount = num;
- else { SysBeep(1);
- NumToString(stageCount, text);
- SetIText(itemHdl,text);
- if (itemHit == IT_OK) itemHit = -1;
- }
- break;
- }
- lastItem = itemHit;
- }
-
- switch ( itemHit ) {
- case IT_OK :
- gNumberSteps = stageCount;
- done = true;
- break;
- case IT_CANCEL : done = true; break;
- case IT_LINEAR:
- linear = !linear;
- GetDItem(theDialog,IT_LINEAR,&itemType,&itemHdl,&itemRect);
- SetCtlValue((ControlHandle)itemHdl,linear);
- break;
- }
- }
- CloseDialog(theDialog);
- SetGWorld(savePort,saveGD);
- } /* End of () */
-
- /********************************************
-
- Allocate the image buffers for the processing,
- when the 1st Picture window is opened!
-
- Creates the following GWorld offscreen buffers:
- gDstWorld, gBufferWorld, gWorld, gAltWorld
-
- Note: Try to allocated from program memory,
- if none try Finder's temp memory!
- ********************************************/
-
- OSErr AllocateBuffers()
- { Rect rect = gOriginalPicFrame;
- OSErr result = 0;
- short depth = gStandardP.depth > 32 ? (gStandardP.depth-32) : gStandardP.depth;
- CTabHandle clut = nil;
-
- OffsetRect(&rect,-rect.left,-rect.top);
-
- if ( gStandardP.depth > 32 )
- clut = GetCTable(gStandardP.depth);
-
- if ( gDstWorld ) { /* Area used to create the image to be added to movie */
- DisposeGWorld(gDstWorld); gDstWorld = nil;
- }
-
- if ( gWorld ) { /* Area used to hold the source image */
- DisposeGWorld(gWorld); gWorld = nil;
- }
-
- if ( gAltWorld ) { /* Area used to hole the 2nd image of crossfades */
- DisposeGWorld(gAltWorld); gAltWorld = nil;
- }
-
- if ( gBufferWorld ) { /* used to preform oversampling */
- DisposeGWorld(gBufferWorld); gBufferWorld = nil;
- }
-
- if ( (result=NewGWorld(&gWorld,depth,&rect,clut,nil,0)) != 0 ) {
- if ( (result=NewGWorld(&gWorld,depth,&rect,clut,nil,useTempMem)) != 0 ) {
- Error("NewGWorld Failed",result); goto done;
- }
- }
- if ( (result=NewGWorld(&gAltWorld,depth,&rect,clut,nil,0)) != 0 ) {
- if ( (result=NewGWorld(&gAltWorld,depth,&rect,clut,nil,useTempMem)) != 0 ) {
- Error("NewGWorld Failed",result); goto done;
- }
- }
- if ( (result=NewGWorld(&gDstWorld,depth,&rect,clut,nil,0)) != 0 ) {
- if ( (result=NewGWorld(&gDstWorld,depth,&rect,clut,nil,useTempMem)) != 0 ) {
- Error("NewGWorld Failed",result); goto done;
- }
- }
-
- if ( (result=NewGWorld(&gBufferWorld,depth,&rect,clut,nil,0)) != 0 ) {
- if ( (result=NewGWorld(&gBufferWorld,depth,&rect,clut,nil,useTempMem)) != 0 ) {
- Error("NewGWorld Failed",result); goto done;
- }
- }
-
- done:
- if ( result ) { /* Errors free buffers */
- if ( gWorld ) DisposeGWorld(gWorld);
- if ( gAltWorld ) DisposeGWorld(gAltWorld);
- if ( gDstWorld ) DisposeGWorld(gDstWorld);
- if ( gBufferWorld ) DisposeGWorld(gBufferWorld);
- gWorld= nil;
- gAltWorld= nil;
- gDstWorld= nil;
- gBufferWorld= nil;
- }
- if ( clut ) DisposeCTable(clut);
- return(result);
- } /* End of () */
-
-
- /*********************************************
-
- Show a preview of some stage in the process.
-
- ********************************************/
- void DoPreview(Boolean dialog)
- {
- #define PV_DLOG 129
- #define IT_STAGE 4
- #define IT_OK 1
- #define IT_CANCEL 2
-
- CGrafPtr savePort;
- DialogPtr theDialog;
- short itemType;
- Handle itemHdl;
- Rect itemRect;
- short itemHit,lastItem = -1;
- Boolean done = false;
- Point tp;
- GDHandle saveGD;
- long num;
- Str31 numStr;
-
- static long whichStage = 15;
-
- if (!gDstWorld || !gWorld || !gAltWorld) { SysBeep(0); return; }
-
- if (dialog) {
-
- if ((theDialog = GetNewDialog(PV_DLOG, nil, (WindowPtr) -1)) == nil )
- return;
-
- GetMouse(&tp);
- GetGWorld(&savePort,&saveGD);
- SetPort(theDialog);
- GetDItem(theDialog,IT_OK,&itemType,&itemHdl,&itemRect);
- PenSize(3,3); InsetRect(&itemRect,-4,-4); FrameRoundRect(&itemRect,16,16);
-
- GetDItem(theDialog,IT_STAGE,&itemType,&itemHdl,&itemRect);
- NumToString(whichStage, numStr); SetIText(itemHdl,numStr);
-
- SelIText(theDialog,IT_STAGE,0,32767);
-
- while ( !done ) {
- ModalDialog(nil, &itemHit);
-
- if ( itemHit != lastItem ) { /* Check number, if user goes to another control */
- switch( lastItem ) {
- case IT_STAGE :
- GetDItem(theDialog,IT_STAGE,&itemType,&itemHdl,&itemRect);
- GetIText(itemHdl,numStr);
- StringToNum(numStr, &num);
- if ( num > 0 && num <= gNumberSteps )
- whichStage = num - 1;
- else {
- SysBeep(1);
- NumToString(whichStage,numStr);
- SetIText(itemHdl,numStr);
- if (itemHit == IT_OK) itemHit = -1;
- }
- break;
- }
- lastItem = itemHit;
- }
-
- switch ( itemHit ) {
- case IT_OK : done = true;
- break;
- case IT_CANCEL : whichStage = 0;
- done = true;
- break;
- }
- }
- CloseDialog(theDialog);
- } else { /* End if Dialog */
- whichStage++;
- if (whichStage >= gNumberSteps) whichStage = 0;
- }
-
- itemRect = gSrcWindow->portRect;
- SetGWorld(gSrcWindow,nil);
- LocalToGlobal((Point *)&itemRect.top); LocalToGlobal((Point *)&itemRect.bottom);
- OffsetRect(&itemRect,20,20);
- if ( gOversample ) {
- itemRect.right = itemRect.left + (itemRect.right-itemRect.left)/2;
- itemRect.bottom = itemRect.top + (itemRect.bottom-itemRect.top)/2;
- }
-
- SetGWorld(savePort,saveGD);
- if ( gDstWindow ) { /* Use open Dest. Window, if same size */
- Boolean same;
-
- OffsetRect(&itemRect,-itemRect.left,-itemRect.top);
- same = EqualRect(&itemRect, &gDstWindow->portRect);
- LocalToGlobal((Point *)&itemRect.top); LocalToGlobal((Point *)&itemRect.bottom);
- if (!same) {
- CloseWindow((WindowPtr)gDstWindow); gDstWindow = nil;
- }
- }
-
- if (!gDstWindow )
- if ( (gDstWindow = (CWindowPtr)NewCWindow(nil,&itemRect,"\pPreview",true,
- zoomDocProc,(WindowPtr)-1,true,0)) == nil ) {
- Error("NewCWindow Failed",0); goto done;
- }
-
- BringToFront((WindowPtr)gDstWindow);
- HiliteWindow((WindowPtr)gDstWindow,true);
- SetGWorld((CGrafPtr)gDstWorld,nil);
- PaintRect(&gDstWorld->portRect);
-
- // Assume: if ( gDstWorld && gWorld && gAltWorld )
- DoStage(whichStage,gNumberSteps,gReverse);
-
- if (OptionDown()) gFrameNumber = whichStage; /* Add Frame Number to Preview */
- SetGWorld((CGrafPtr)gDstWindow,nil);
- InvalRect(&gDstWindow->portRect);
- DoUpdate(gDstWindow);
- gFrameNumber = -1;
-
- done:
- SetGWorld(savePort,saveGD);
- } /* End of () */
-
- /********************************************
-
- Make a source window
-
- ********************************************/
-
- CWindowPtr MakeSWindow(Rect *frame,StringPtr name,GWorldPtr buffer)
- { CWindowPtr wind;
-
- if ( (wind = (CWindowPtr)NewCWindow(nil,frame,name,false, zoomDocProc,(WindowPtr)-1,true,0)) == nil ) {
- Error("NewCWindow Failed",0); return(nil);
- }
- ShowWindow((WindowPtr)wind);
- BringToFront((WindowPtr)wind); HiliteWindow((WindowPtr)wind,true);
- SetWRefCon((WindowPtr)wind,(long)buffer);
- return(wind);
- } /* End of () */
-
- /********************************************
-
- Open a file.
-
- ********************************************/
- OSErr DoOpen(FSSpec *fsp)
- { long result = noErr;
- Rect zpFrame;
- GWorldPtr saveWorld;
- GDHandle saveGD;
- short oFile = -1;
- StandardFileReply theSFR;
- Boolean HasCompression = true;
- long resp;
-
- if ( Gestalt(gestaltCompressionMgr, &resp) != noErr || resp < 15 ) HasCompression = false;
-
- GetGWorld(&saveWorld,&saveGD);
- if ( fsp == nil ) {
- SFTypeList types = { 'PICT','JFIF',0 };
- if ( gHasNewStdFile ) {
- if (!HasCompression) StandardGetFile(nil,2,types,&theSFR);
- else StandardGetFilePreview(nil,2,types,&theSFR);
- } else {
- SFReply osfr;
- Point pt = {100,100};
-
- SFGetFile(pt,(ConstStr255Param)"",nil,1,types,nil,&osfr);
- theSFR.sfGood = osfr.good;
- theSFR.sfReplacing = osfr.copy;
- theSFR.sfType = osfr.fType;
- if ( osfr.good ) FSMakeFSSpec(osfr.vRefNum,0L,osfr.fName,&theSFR.sfFile);
- }
- if ( !theSFR.sfGood ) return(1);
- } else {
- theSFR.sfFile = *fsp;
- }
-
- if ( FSpOpenDF(&theSFR.sfFile,fsRdPerm,&oFile) ) {
- result = -1; goto done;
- }
-
-
- /************************************************
- * Get the picture frame, to see how big of a window to make.
- ************************************************/
-
- if ( GetPictureFileHeader(oFile,&gOriginalPicFrame,nil ) ) {
- result = -1; goto done;
- }
-
- if ( gSrcWindow == nil ) { /* Open Image 1's window */
- OffsetRect(&gOriginalPicFrame,-gOriginalPicFrame.left,-gOriginalPicFrame.top);
- if ( gOversample ) {
- gOriginalPicFrame.right *= 2;
- gOriginalPicFrame.bottom *= 2;
- }
- zpFrame = gOriginalPicFrame;
-
- if ( (result=AllocateBuffers()) != 0 ) goto done; /* Make GWorld buffers, */
- /* if no windows open yet */
-
- OffsetRect(&zpFrame,50,50);
- gSrcWindow = MakeSWindow(&zpFrame,theSFR.sfFile.name,gWorld);
- SetGWorld((CGrafPtr)gWorld,nil);
- if ( (result=DrawPictureFile(oFile,&gWorld->portRect,nil)) != 0 ) {
- Error("DrawPictureFile Failed",result); goto done;
- }
-
- } else { /* Open Image 2's window */
- zpFrame = gOriginalPicFrame;
- OffsetRect(&zpFrame,70,70);
- gAltWindow = MakeSWindow(&zpFrame,theSFR.sfFile.name,gAltWorld);
- SetGWorld((CGrafPtr)gAltWorld,nil);
- if ( (result=DrawPictureFile(oFile,&gAltWorld->portRect,nil)) != 0 ) {
- Error("DrawPictureFile Failed",result); goto done;
- }
- }
- done:
- if ( oFile != -1 ) FSClose(oFile);
- SetGWorld(saveWorld,saveGD);
- return(result);
- } /* End of () */